# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>

_gemname=bindata
pkgname=ruby-${_gemname}
pkgver=2.4.14
pkgrel=1
pkgdesc='BinData - Parsing Binary Data in Ruby'
url='https://github.com/dmendel/bindata'
arch=('any')
license=('custom:BSDL')
depends=('ruby')
makedepends=('ruby-rake' 'ruby-rdoc' 'ruby-bundler')
checkdepends=('ruby-minitest')
options=('!emptydirs')
source=(${url}/archive/v${pkgver}/${pkgname}-v${pkgver}.tar.gz)
sha512sums=('ac9d8037c0f1d0f25573085446f3e30426babb90885b9f06f855eaef5dae08e1c15b16e2ca452bac53968e080b21cbd53b78f851b1513e4441604c6a9dddf16f')
b2sums=('c69f03bbc97f3a6caf084ac4313a15505f48261441125c51168ad6ae5cbd961e14645c9249e47c83c44b3e2235099820f65db4028d830623484111865ce3d4c5')

prepare() {
  cd ${_gemname}-${pkgver}
  sed -r 's|~>|>=|g' -i ${_gemname}.gemspec
  sed -r 's|, "< .*"||g' -i ${_gemname}.gemspec
  sed 's|git ls-files|find|' -i ${_gemname}.gemspec
  sed -e '/coveralls/d' -e '/Coveralls/d' -i ${_gemname}.gemspec test/*.rb
}

build() {
  cd ${_gemname}-${pkgver}
  gem build ${_gemname}.gemspec
}

check() {
  cd ${_gemname}-${pkgver}
  rake test
}

package() {
  cd ${_gemname}-${pkgver}
  local _gemdir="$(gem env gemdir)"
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "${pkgdir}${_gemdir}" \
    --bindir "${pkgdir}/usr/bin" \
    ${_gemname}-${pkgver}.gem

  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 COPYING -t "${pkgdir}/usr/share/licenses/${pkgname}"

  cd "${pkgdir}/${_gemdir}"
  rm -rf cache gems/${_gemname}-${pkgver}/{ext,lib/*/*.so,man} \
    extensions/*/*/${_gemname}-${pkgver}/{mkmf.log,gem_make.out}
}

# vim: ts=2 sw=2 et:
